import pysyslogclient


class SysLog:

    def __init__(self, **kwargs):
        self.server = None
        self.port = None
        self.proto = None
        if kwargs:
            self.init(**kwargs)

    def init(self, server, port: int, proto):
        self.server = server
        self.port = port
        self.proto = proto

    def send(self, messages, facility=1, severity=1, **kwargs):
        """单条 批量发送"""
        client = pysyslogclient.SyslogClientRFC5424(server=self.server, port=self.port, proto=self.proto)
        if isinstance(messages, str):
            messages = [messages]
        for message in messages:
            client.log(message,
                       severity=severity,
                       facility=facility, **kwargs
                       )
        client.close()


if __name__ == '__main__':
    message_ = '{"a": "b"}'
    syslog = SysLog(
        proto='udp',
        server='192.168.101.29',
        port=514
    )
    syslog.send(message_, facility=16, severity=0)
